import { Alert } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from '../../util/http';

export const authLogin = async (username, password) => {
    try {
        const res = await axios.post('/auth/login', {
            username,
            password,
        });
        const { accessToken } = res.data;
        await AsyncStorage.setItem('accessToken', accessToken);
        await AsyncStorage.removeItem('userInfo');
        return res.data;
    } catch (e) {
        Alert.alert('请求失败', e.message);
        return null;
    }
};
